package com.tengol.course.spring.boot.customer.starter.config;

import com.tengol.course.spring.boot.customer.starter.service.HelloService;
import com.tengol.course.spring.boot.customer.starter.service.impl.HelloServiceImpl;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * HelloAutoConfiguration
 *
 * @author dongrui
 * @date 2020/05/17
 */
@Configuration
@ConditionalOnWebApplication
@EnableConfigurationProperties(HelloProperties.class)
public class HelloAutoConfiguration {
    private HelloProperties helloProperties;

    public HelloAutoConfiguration(HelloProperties helloProperties) {
        this.helloProperties = helloProperties;
    }

    @Bean
    @ConditionalOnMissingBean(value = HelloService.class)
    public HelloService helloService(){
        return new HelloServiceImpl(helloProperties);
    }
}
